import Vue from 'vue'
import Vuex from 'vuex'

import { getStorage, setStorage } from '@/utils/storage'

// import createLoger from 'vuex/dist/logger'
// import createPersistedstate from 'vuex-persistedstate'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    user: getStorage('user'),
    cacheArr: ['Layout']
  },
  mutations: {
    // 存储token
    setToken (state, payload) {
      state.user = payload
      setStorage('user', state.user)
    },
    // 添加组件缓存
    addCache (state, payload) {
      if (!state.cacheArr.includes(payload)) {
        state.cacheArr.push(payload)
      }
    },
    // 移除组件缓存
    removeCache (state, payload) {
      const index = state.cacheArr.indexOf(payload)
      if (index !== -1) {
        state.cacheArr.splice(index, 1)
      }
    }
  },
  actions: {},
  modules: {}
  // plugins: [createLoger(), createPersistedstate()]
})
